# -*- coding:utf-8 -*-
# author: helili
# @Time: 2020/11/5 下午3:46
from UICaseRunner.common import operate_file
from UICaseRunner.common.function_assistant import function_dollar


class TestCaseOperate:
    # 调用这个类需要传环境，后续处理
    def __init__(self):
        self.variable_element_dict = operate_file.get_yam("../resource/login/login_element_config.yml")
        # 定义一个变量名与提取的结果字典
        # cls.variable_result_dict与self.variable_result_dict都是本类的公共属性
        self.test_case_data_list = []
        # 定义一个测试用例数据列表

    """
        替换用例步骤中的 ${variable} 中的变量
    """
    def replace_dollar_case(self, item, variable_element_dict, env_account_config):
        # 操作步骤名称
        step_name = item.get("step_name")
        operate_elem = item.get("operate_elem")
        operate_type = item.get("operate_type")
        msg = item.get("msg")

        # 遍历并替换用例文件中的引用的变量
        if self.variable_element_dict:
            # 如果变量名与提取的结果字典不为空
            if operate_elem:
                operate_elem = function_dollar(operate_elem, variable_element_dict.items())
                item["operate_elem"] = operate_elem
            if msg:
                msg = function_dollar(msg, env_account_config.items())
                item["msg"] = msg
        self.test_case_data_list.append((
            operate_elem,
            step_name,
            operate_type,
            msg
        ))
        return item
